package com.heyqing.topic.GetRow_0119;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;

/**
 * ClassName:GetRow
 * Package:com.heyqing.topic.GetRow_0119
 * Description:
 *
 * @Date:2024/9/15
 * @Author:Heyqing
 */
public class GetRow {
    public List<Integer> getRow(int rowIndex) {
        List<List<Integer>> result = new ArrayList<>();
        List<Integer> temp;
        for (int i = 0; i < rowIndex + 1; i++) {
            temp = new ArrayList<>(i + 1);
            if (i == 0) temp.add(1);
            else {
                for (int j = 0; j <= i; j++) {
                    if (j == 0 || j == i) temp.add(1);
                    else temp.add(result.get(i - 1).get(j - 1) + result.get(i - 1).get(j));
                }
            }
            result.add(temp);
        }
        return result.get(rowIndex);
    }

    public static void start() {
        GetRow getRow = new GetRow();
        List<Integer> res = getRow.getRow(5);
        System.out.println(res);
    }
}
